// pages/rfid_binds/pandi/pandi.js
import Dialog from '../../../miniprogram_npm/@vant/weapp/dialog/dialog';
const mybehavior = require("../../../behaviors/requests")
Page({
  /**
   * 页面的初始数据
   */
  behaviors: [mybehavior],
  data: {
    material_order: "",
    quantity: 0,
    value: "",
    columns: ["排洪渠", "河边仓库"],
    showPicker: false
  },
  onSubmit() {
    let that = this;
    if (this.data.material_order == "") {
      wx.showToast({
        title: '批次不能为空',
        icon: "error"
      })
    } else if (this.data.value == "") {
      wx.showToast({
        title: '仓库不能为空',
        icon: "error"
      })
    } else {
      Dialog.confirm({
          title: "信息确认",
          message: "物料单号:" +
            this.data.material_order +
            "\n仓库:" + this.data.value +
            "\n数量:" + this.data.quantity
        })
        .then(() => {
          that.post("https://logisticsengineering.gree.com/rfid_api/rfid_manage/pandian", {
              material_order: this.data.material_order,
              status: this.data.value == "排洪渠" ? "S3" : "S4",
              quantity: this.data.quantity
            }).then(res => {
              wx.showToast({
                title: '成功!',
              })
              that.setData({
                material_order: "",
                value: "",
                quantity: ""
              })
            })
            .catch((e) => {
              wx.showToast({
                title: e.msg,
                icon: "error"
              })
            })
        })
    }
  },
  scan() {
    const self = this;
    wx.scanCode().then((res) => {
      const hardware_code = res.result;
      self.setData({
        material_order: hardware_code
      });
    });
  },
  onClear() {
    Dialog.confirm({
      title: "数据重置",
      message: "确认数据重置？"
    }).then(() => {
      this.material_order = "";
      this.value = null;
      this.quantity = 0;
      Toast.success("数据已清零");
    });
  },
  onConfirm(event) {
    const {
      picker,
      value,
      index
    } = event.detail;
    this.setData({
      value: value,
      showPicker: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },
  setShowFalse() {
    this.setData({
      showPicker: false
    })
  },
  setShowTrue() {
    this.setData({
      showPicker: true
    })
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})